﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VLUSM_DataAccess.Repositories
{
    public class LoaiHocBongRepository : GenericRepository<MainDataContainer>
    {
        public LoaiHocBongRepository(string connectionString) : base(connectionString, "MainData") { }
        public LoaiHocBongRepository(MainDataContainer context) : base(context) { }

        public LoaiHocBong GetSingleByID(int IDFilter)
        {
            var query = this.GetFirst<LoaiHocBong>(d => d.ID == IDFilter); 
            return query;
        }

        public LoaiHocBong GetSingleByTen(string TenFilter)
        {
            var query = this.GetFirst<LoaiHocBong>(d => d.TenGoi == TenFilter);
            return query;
        }

        public IEnumerable<LoaiHocBong> GetAll()
        {
            var query = this.GetAll<LoaiHocBong>();
            return query;
        }

        public void Save(LoaiHocBong obj)
        {
            try
            {
                if (obj.ID != 0)
                {
                    this.Attach<LoaiHocBong>(obj);
                }
                else
                {
                    this.Add<LoaiHocBong>(obj);
                }
            }
            catch { }
        }

        public void Remove(LoaiHocBong obj)
        {
            this.Delete<LoaiHocBong>(obj);
        }

        public void Remove(int IDFilter)
        {
            var obj = this.GetSingleOrDefault<LoaiHocBong>(h => h.ID == IDFilter);
            this.Delete<LoaiHocBong>(obj);
        }
    }
}
